package com.exercises;

public class Exercise477 {
    public int totalHammingDistance(int[] nums) {
        int total = 0, length = nums.length;
        for (int i = 0; i < 30; i++) {
            int bitOne = 0;
            for (int n : nums) {
                //nums数组中二进制i位是1的值的数量
                bitOne += (n >> i & 1);
            }
            //nums数组中二进制i位不是1的值的数量
            int bitZero = length - bitOne;
            total += bitOne * bitZero;
        }
        return total;
    }
}
